package cn.autumnorange.app.util.api;

import cn.autumnorange.app.common.api.feign.AbstractFallbackFactory;
import cn.autumnorange.app.common.dto.ResultDto;
import cn.autumnorange.app.util.api.dto.OrderDto;
import feign.hystrix.FallbackFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;

@Component
public class TimeServiceFallbackFactory extends AbstractFallbackFactory implements FallbackFactory  {
  @Override
  public TimeService create(Throwable throwable) {
    return new TimeService() {
      public ResponseEntity<ResultDto<String>> timestampToYYMMDD(long timestamp) {
        //                return ResultDto.createErrorResult(throwable.getMessage());
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
            .body(ResultDto.createResult(errorStatus.value(),null,throwable.getMessage(),null,System.currentTimeMillis(),throwable.getCause().getMessage()));
      }

      @Override
      public ResponseEntity<ResultDto<String>> getAnnotation(String className, String methodName, String annotationName) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .body(ResultDto.createResult(errorStatus.value(),null,throwable.getMessage(),null,System.currentTimeMillis(),throwable.getCause().getMessage()));
      }

      @Override
      public ResponseEntity<ResultDto<OrderDto>> updOrder(OrderDto orderDto) throws Exception{
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .body(ResultDto.createResult(errorStatus.value(),null,throwable.getMessage(),null,System.currentTimeMillis(),throwable.getCause().getMessage()));
      }
    };
  }
}
